package com.lipo.springmvc;

import java.io.PrintWriter;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lipo.mapper.UserMapper;
import com.lipo.model.User;

@Controller
@RequestMapping("/mvc")
public class MvcController {

	@Autowired
	private UserMapper userMapper;
	
	@RequestMapping("/getjson")
	public void setPull(String name,PrintWriter pw){
		pw.print(zuheJson(name));
	}
	
	@RequestMapping("/index")
	public String toMain(){
		return "my";
	}
	
	private String zuheJson(String name) {
		JSONObject json = new JSONObject();
		json.put("code", "1");
		JSONObject data = new JSONObject();
		if (name != null) {
			data.put("name", name);
		}
		json.put("data", data);
		json.put("msg", "成功登陆");
		System.out.println(json.toString());
		return json.toString();
	}
	
	@RequestMapping("/getUser")
	public void getUser(PrintWriter pw){
		User user = userMapper.findById(1);
		pw.print("username:"+user.getUserName()+",age:"+user.getUserAge());
		
	}
	
}
